import { DEFAULTLAYER } from '@/libs/constant'

class Image {
  constructor(props) {
    this.type = 'image'
    this.layer = DEFAULTLAYER - 1
    this.image = props.image
    this.startX = props.startX
    this.startY = props.startY
    this.width = props.width
    this.height = props.height
  }

  get src() {
    return this.image.src
  }

  getType() {
    return this.type
  }

  getLayer() {
    return this.layer
  }

  setLayer(layer) {
    this.layer = layer
  }

  changePosition(diffX, diffY) {
    this.startX += diffX
    this.startY += diffY
  }

  inside(x, y) {
    if (
      x >= this.startX &&
      x <= this.startX + this.width &&
      y >= this.startY &&
      y <= this.startY + this.height
    ) {
      return true
    }
    return false
  }

  draw(ctx) {
    ctx.drawImage(this.image, this.startX, this.startY, this.width, this.height)
  }
}

export default Image
